from socket import *
import time
import threading

address = ('192.168.2.252', 50004)

def Test(id):
    sock = socket(AF_INET, SOCK_STREAM)
    sock.connect(address)

    sock.send(id)
    while True:
        sock.send('\x53\x54\x41\x52\x54\x46\x35\xc2\x8f\x5c\x53\x54\x4f\x50\x46\x3d\x70\xa3\xd7\x53\x54\x45\x50\x00\x05\x3e\x2d')

        buff = sock.recv(8192)
        print buff

        sock.send('GETDATA')

        while True:
            buff = sock.recv(8192)
            #print "".join(["\'\\x%02X\', " % ord(k) for k in buff])
            if buff[-7:] == 'DATAEND':
                print 'Data end'
                break

        time.sleep(0.1)
    sock.close()

if __name__ == '__main__':

    ids = {'\x03', '\x0b', '\x06', '\x07'}
    for i in ids:
        th = threading.Thread(target = Test, args = {i})
        #th.setDaemon(True)
        th.start()
    
    th.join()
